package com.csdj.controller;


import com.csdj.config.LogAnnotation;
import com.csdj.entity.Cart;
import com.csdj.entity.Foodlist;
import com.csdj.service.ICartService;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zwy
 * @since 2024-12-11
 */
@RestController
@RequestMapping("/cart")
@Slf4j
public class CartController {
    @Resource
    private ICartService cs;

    @GetMapping("queryCart")
    @LogAnnotation(type = "Get", names = "查询购物车")
    public Object queryCart(Cart cart) {
        List<Cart> carts = cs.queryCart(cart);
        return carts;
    }

    @GetMapping("getCartPage")
    @LogAnnotation(type = "Get", names = "分页查询商品")
    public Object getCartPage( int currentPage,  int pageSize) {
        // 执行查询
        PageInfo<Cart> carts = cs.queryPagecart(currentPage, pageSize);
        return carts;
    }

    @DeleteMapping("/cartId")
    @LogAnnotation(type = "Get", names = "删除商品")
    public Object delete(@RequestParam(required = false) Integer cartId){
        log.info("删除商品：{}",cartId);
        return cs.delete(cartId);
    }

}
